package com.eningqu.aipen.ui.adapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ItemMedicalBinding;
import com.eningqu.aipen.logic.model.medical.MedicalBookBean;
import com.eningqu.aipen.ui.medical.MedicalNodeActivity;
import com.eningqu.aipen.utils.GlideUtils;

import java.util.List;

/**
 * Package:com.eningqu.aipen.ui.adapter
 * Author:starr
 * Time:2023/11/16 12:33
 * Description:
 */
public class MedicalAdapter extends RecyclerView.Adapter<MedicalAdapter.MedicalViewHolder> {

    private List<MedicalBookBean.PageDTO> list;


    public MedicalAdapter(List<MedicalBookBean.PageDTO> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MedicalViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ItemMedicalBinding binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.item_medical, viewGroup, false);
        MedicalViewHolder holder = new MedicalViewHolder(binding.getRoot());
        return holder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull MedicalViewHolder holder, int i) {

        ItemMedicalBinding binding = DataBindingUtil.getBinding(holder.itemView);
        MedicalBookBean.PageDTO medicalBean = list.get(i);
        assert binding != null;
        binding.tvRiqi.setText(medicalBean.emrBlUpdate.substring(0, 10));
        binding.tvInfo.setText("出生日期:" + medicalBean.hzInfoEntity.emrHzBirth);
        binding.tvPhone.setText("联系电话:" + medicalBean.hzInfoEntity.emrHzPhone);
        binding.tvHzName.setText(medicalBean.hzInfoEntity.emrHzName);
        GlideUtils.loadCircleImage(holder.itemView.getContext(), medicalBean.hzInfoEntity.emrHzImg, binding.ivUser);
        if (medicalBean.hzInfoEntity.emrHzSex.equals("男")) {
            Glide.with(holder.itemView).load(R.drawable.ic_boy).into(binding.ivSex);
        } else {
            Glide.with(holder.itemView).load(R.drawable.ic_girl).into(binding.ivSex);
        }
        Integer blId = medicalBean.emrBlId;//病历编号
        Bundle bundle = new Bundle();
        bundle.putInt("blId", blId);
        bundle.putSerializable("blhz", medicalBean);//病历联合患者信息实体
        binding.clItemMedicalRoot.setOnClickListener(v -> MedicalNodeActivity.startAction(v.getContext(), bundle));
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class MedicalViewHolder extends RecyclerView.ViewHolder {

        public MedicalViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
